﻿using System;
using System.Text;
using System.Windows.Forms;
using System.Configuration;
using System.Threading;
using System.Collections;
using System.Drawing;

namespace NGI_Auxiliares
{
    public class FuncionesFormulario
    {

        public static void ModificarAltura(Int32 YFinal, Form FormularioAModificar)
        {
            
            if (FormularioAModificar.Height > YFinal)
            {
                //Debe achicar
                for (; FormularioAModificar.Height > YFinal; FormularioAModificar.Height -= 1, Thread.Sleep(20)) { }
            }
            else
            {
                //Debe agrandar
                for (; FormularioAModificar.Height < YFinal; FormularioAModificar.Height += 1, Thread.Sleep(20)) { }
            }
        }

        public static void CargarCombo(ComboBox cboCombo, ArrayList arrDatos, string strDiplayMember, string strValueMember)
        {
            cboCombo.DataSource = arrDatos;
            cboCombo.DisplayMember = strDiplayMember;
            cboCombo.ValueMember = strValueMember;
        }

        public static void CargarCombo(DataGridViewComboBoxColumn cboCombo, ArrayList arrDatos, string strDiplayMember, string strValueMember)
        {
            cboCombo.DataSource = arrDatos;
            cboCombo.DisplayMember = strDiplayMember;
            cboCombo.ValueMember = strValueMember;
        }

        public static void CargarLista(ListBox lstList, ArrayList arrDatos, string strDiplayMember, string strValueMember)
        {
            try
            {
                lstList.DataSource = arrDatos;
                lstList.DisplayMember = strDiplayMember;
                lstList.ValueMember = strValueMember;
            }
            catch (Exception ex)
            {


            }
        }

        public static Boolean TodosLosCamposValidos(ArrayList CamposYDescripcion)
        {
            Boolean Valido = true;
            foreach (Validacion CampoYDescripcion in CamposYDescripcion)
            {
                if (!CampoYDescripcion.EsValido())
                {
                    Valido = false;
                    if (CampoYDescripcion.Etiquetas != null)
                    {
                        foreach (Control Etiqueta in CampoYDescripcion.Etiquetas)
                            Etiqueta.ForeColor = Color.Red;

                        if (((TextBox)CampoYDescripcion.Campos[0]).Text.Length > 0)
                            CampoYDescripcion.EtiquetaAdicional.Visible = true;
                    }
                    else
                    {
                        if (CampoYDescripcion.Etiqueta != null) CampoYDescripcion.Etiqueta.ForeColor = Color.Red;
                    }
                }
            }

            return Valido;
        }
    }
}
